package com.activepad.module.customer.dao.impl;

import com.activepad.common.interfaces.SurveyDaoImpl;
import com.activepad.module.customer.dao.EnterpriseAccountDao;
import com.activepad.module.customer.pojo.AccountVo;
import com.activepad.module.entity.customer.EnterpriseAccount;
import com.activepad.module.entity.customer.EnterpriseCustomer;
import com.common.util.BeanUtils;

/**
 * 企业用户账户数据访问接口实现类
 * 
 * 
 * @author 孙树林
 * 
 */
public class EnterpriseAccountDaoImpl extends SurveyDaoImpl implements EnterpriseAccountDao {

	/**
	 * 查找企业客户账户资料
	 * 
	 * @param id
	 * @return
	 */
	@Override
	public AccountVo findEnterpriseAccount(Integer id) {
		EnterpriseAccount enterpriseAccount = (EnterpriseAccount) hibernateDataAccess.getEntity(EnterpriseAccount.class, id);
		AccountVo accountVo = new AccountVo();
		BeanUtils.copyPropertiesNotNull(enterpriseAccount, accountVo);
		return accountVo;
	}

	/**
	 * 保存企业用户账户资料
	 * 
	 * @param accountVO
	 */
	@Override
	public void saveEnterpriseAccount(AccountVo accountVo) {
		EnterpriseAccount enterpriseAccount = new EnterpriseAccount();
		BeanUtils.copyPropertiesNotNull(accountVo, enterpriseAccount);
		
		EnterpriseCustomer enterpriseCustomer = (EnterpriseCustomer) hibernateDataAccess.loadEntity(EnterpriseCustomer.class, accountVo.getCustId());
		enterpriseAccount.setEnterpriseCustomer(enterpriseCustomer);
		
		hibernateDataAccess.saveEntity(enterpriseAccount);
	}

	/**
	 * 编辑企业用户账户资料
	 * 
	 * @param accountVO
	 */
	@Override
	public void updateEnterpriseAccount(AccountVo accountVo) {
		EnterpriseAccount enterpriseAccount = (EnterpriseAccount) hibernateDataAccess.loadEntity(EnterpriseAccount.class, accountVo.getId());
		BeanUtils.copyPropertiesNotNull(accountVo, enterpriseAccount);
		
		hibernateDataAccess.updateEntity(enterpriseAccount);
	}

}
